package Ja057;

import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{

	private String name;
	private int age;

	
	public PersonSortable(String name, int age){
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return  name + "-" + age ;
	}

	@Override
	public int compareTo(PersonSortable o) {	
		if(this.name.compareTo(o.name)==0)
		{
			if(this.age -o.age <0)
				return -1;
			else if(this.age -o.age ==0)
				return 0;
			else
				return 1;
			    
		}
		return name.compareTo(o.name);
	}
	
}

public class Main01 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PersonSortable[] stu = new PersonSortable[n];
		for(int i=0 ; i<n ; i++){
			 stu[i]= new PersonSortable(sc.next(),sc.nextInt() );
		}
	
		Arrays.sort(stu);
		for(int i=0 ; i<n ; i++){
			System.out.println(stu[i]);
		}
	
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}

}
